package com.richfit.barcodesystem_cczt.activitis.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.richfit.barcodesystem_cczt.R;
import com.richfit.barcodesystem_cczt.activitis.model.users.UserInfo;
import com.richfit.barcodesystem_cczt.databinding.ItemBottomBizmenuBinding;

import java.util.List;

public class BottomSheetDialogAdapter extends BaseAdapter {
    private static final int[] MENUS_IMAGES = {
            R.mipmap.icon_submenu1, R.mipmap.icon_submenu2, R.mipmap.icon_submenu3,
            R.mipmap.icon_submenu4, R.mipmap.icon_submenu5, R.mipmap.icon_submenu6,
            R.mipmap.icon_submenu7, R.mipmap.icon_submenu8, R.mipmap.icon_submenu9,
            R.mipmap.icon_submenu10, R.mipmap.icon_submenu11
    };
    ItemBottomBizmenuBinding mView;
    private Context mContext;
    private List<UserInfo.MenusBean> list;

    public BottomSheetDialogAdapter(Context context, List<UserInfo.MenusBean> list) {
        this.mContext = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public UserInfo.MenusBean getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {

        if (view == null) {
            mView = ItemBottomBizmenuBinding.inflate(LayoutInflater.from(mContext));
            view = mView.getRoot();
            view.setTag(mView);
        } else {
            mView = (ItemBottomBizmenuBinding) view.getTag();
        }
        mView.menuTv.setText(getItem(position).getName());
        mView.menuIv.setBackgroundResource(MENUS_IMAGES[position % MENUS_IMAGES.length]);
        return view;
    }
}
